package jfdi;

import jfdi.event.TouchListener;
import android.app.Activity;
import android.os.Bundle;
import android.view.KeyEvent;
import android.view.MotionEvent;
import android.view.View;
import android.view.ViewGroup;
import android.view.Window;

public class NodeActivity extends Activity implements NodeHost {

    RootNode mRoot;

    @Override
    public void onCreate(Bundle bundle) {
        super.onCreate(bundle);
        getWindow().requestFeature(Window.FEATURE_NO_TITLE);
        mRoot = new RootNode(this);
        setContentView(mRoot);
//        View dv = getWindow().getDecorView();
//        ((ViewGroup) dv).removeAllViews();
//        ((ViewGroup) dv).addView(mRoot);
    }

    private void attachView(View v) {
    }
        
    public void setNode(Node tree) {
        mRoot.setNode(tree);
    }

    public Node loadLayout(int id) {
        Node result = null;
        JsonLoader.loadLayout(this, id);
        return result;
    }

    @Override
    public void onPause() {
        super.onPause();
    }

    @Override
    public void onResume() {
        super.onResume();
    }

    @Override
    public void onBackPressed() {
    }

    @Override
    public boolean dispatchKeyEvent(KeyEvent event) {
        return mRoot.dispatchKeyEvent(event);
    }

    @Override
    public boolean dispatchKeyShortcutEvent(KeyEvent event) {
        return mRoot.dispatchKeyShortcutEvent(event);
    }

    @Override
    public boolean dispatchTouchEvent(MotionEvent event) {
        return mRoot.dispatchTouchEvent(event);
    }

    @Override
    public boolean dispatchTrackballEvent(MotionEvent event) {
        return mRoot.dispatchTrackballEvent(event);
    }

    @Override
    public boolean dispatchGenericMotionEvent(MotionEvent event) {
        return mRoot.dispatchGenericMotionEvent(event);
    }

    @Override
    public void addTouchListener(TouchListener tl) {
        mRoot.addTouchListener(tl);
    }
    
    @Override 
    public void removeTouchListener(TouchListener tl) {
        mRoot.removeTouchListener(tl);
    }

    @Override
    public void invalidate() {
        mRoot.invalidate();
    }
    
    @Override
    public void postInvalidate() {
        mRoot.postInvalidate();
    }
}
